<!--{if $events}-->
<ul class="lyear-timeline lyear-timeline-left">
<!--{loop $events $eventval}-->
<li class="lyear-timeline-item dynameic-comment">
    <div class="lyear-timeline-item-dot">
      <span><a href="user.php?uid=$eventval['uid']" title="$eventval['username']" target="_blank">{eval echo avatar_block($eventval['uid']);}</a></span>
    </div>
    <div class="lyear-timeline-item-content">
      <p class="mb-1 text-break" title="$eventval['username']"><strong>$eventval['username']</strong></p>
      <p class="mb-1 text-break">{$eventval[details]}</p>
      <p class="mb-0"><time class="mb-3">{eval echo dgmdate($eventval['dateline'], 'u');}</time><!--{if $eventval['type'] == 1}--><span class="delete-comment color-danger mdi mdi-delete" data-commentid="$eventval[id]"></span><!--{/if}--></p>
    </div>
</li>
<!--{/loop}-->
</ul>
<!--{if $next}-->
{if !isset($tplmore)}
<div class="mb-1 d-grid">
<a href="javascript:;" class="btn btn-link btn-sm text-end {if !isset($tplmore)}btn_dynamic_more {else}btn_dynamic_more_less{/if} {if isset($tplmore)} hide {/if}" onclick="load_dynamic(this,'{eval echo ($next-3)}','{eval if(!is_array($rids)) $rids = (array)$rids;echo implode(',',$rids);}','$_GET['fid']',0);">{lang upload_more}</a>
</div>
<!--{else}-->
<a href="javascript:;" class="btn btn-link btn-sm text-end btn_dynamic_more_less {if isset($tplmore)} hide {/if}" onclick="load_dynamic(this,$next,'{eval if(!is_array($rids)) $rids = (array)$rids;echo implode(',',$rids);}','$pfid',1);">{lang upload_more}</a>
<!--{/if}-->
<!--{/if}-->
<!--{else}-->
<div class="scroll-y">
	<div class="emptyPage">
    	<img src="{MOD_PATH}/images/noFilePage-dynamic.png">
    	<p class="emptyPage-text">{lang no_dynamisc}</p>
    </div>
</div>
<!--{/if}-->
<script type="text/javascript" src="static/atwho/js/jquery.atwho.js"></script>
<script type="text/javascript" src="static/atwho/js/jquery.caret.js"></script>
<script type="text/javascript">
    var gid = '{$gid}';
    var commentfid = '';
    var commentrid='';
    jQuery(document).on('click', '.btn_dynamic_more', function () {
        jQuery('#more_dynameic').show();
    });

    function load_dynamic(obj, next, rid, fid, tplmore) {
        var queryObj = {'next': next};
        if (rid) {
            queryObj.rid = rid;
        } else {
            queryObj.rid = fid;
        }
        
        var adddynamisc = '';
        if (tplmore) adddynamisc = '&adddynamisc=1';
        jQuery.get('{MOD_URL}&op=dynamic&do=loadmoredynamic&gid=' + gid + adddynamisc, queryObj, function (html) {
            if (tplmore) {
                jQuery(obj).replaceWith(html);
            } else {
                jQuery('#rightinfo_content').replaceWith(html);
            }
            _explorer.Scroll();
            jQuery('#leave_message').off("input.commet propertychange.comment").on("input.comment propertychange.comment", function (e) {
                var el = jQuery(this);
                var msg = el.val();
                var disbutton = el.closest('.comment-area').find('button');
                if (msg.length <= 0) {
                    disbutton.addClass("disabled");
                    disbutton.css({'color': 'rgba(55,121,255,0.3)'});
                } else {
                    disbutton.removeClass("disabled");
                    disbutton.css({'color': 'rgba(55,121,255,1)'});
                }
            });
            jQuery('#leave_message').focus(function () {
                var el = jQuery(this);
                var msg = el.val();
                var disbutton = el.closest('.comment-area').find('button');
                if (msg.length <= 0) {
                    disbutton.addClass("disabled");
                    disbutton.css({'color': 'rgba(55,121,255,0.3)'});
                } else {
                    disbutton.removeClass("disabled");
                    disbutton.css({'color': 'rgba(55,121,255,1)'});
                }
            })

        });
    }
   jQuery(function(){
        if (gid > 0 && jQuery('#commentid').length > 0) {
            commentfid = jQuery('#commentid').find('input[name=fid]').val();
            commentrid = jQuery('#commentid').find('input[name=rid]').val();
            var cachequeryMentions = [], itemsMentions;
            var querystr = '';
            if(commentfid){
                querystr = '&fid='+commentfid;
            }else{
                querystr = '&rid='+commentrid;
            }
            jQuery('#leave_message').atwho({
                at: "@",
                data: '{DZZSCRIPT}?mod=explorer&op=group&do=group_ajax&operation=getAtData&gid=' + gid+querystr,
                callbacks: {
                    remote_filter: function (query, render_view) {
//                        console.log(query);
                        var thisVal = query,
                            self = jQuery(this);
                        if (!self.data('active') && thisVal.length >= 1) {
                            self.data('active', true);
                            itemsMentions = cachequeryMentions[thisVal]
                            if (typeof itemsMentions == "object") {
                                render_view(itemsMentions);
                            } else {
                                if (self.xhr) {
                                    self.xhr.abort();
                                }
                                self.xhr = jQuery.getJSON('{DZZSCRIPT}?mod=explorer&op=group&do=group_ajax&operation=getAtData&gid=' + gid+querystr,{
                                    term: thisVal
                                }, function (data) {
                                    cachequeryMentions[thisVal] = data
                                    render_view(data);
                                });
                            }
                            self.data('active', false);
                        }
                    }
                },
                tpl: "<li data-value='@[${name}:${id}]' title='${title}'>${avatar}&nbsp;${name}</li>",
                search_key: "searchkey",
                start_with_space: false,
                limit: 5,
                max_len: 20,
                display_timeout: 300
            });
        }

    })
    jQuery(document).off('click.commentdelete').on('click.commentdelete','.delete-comment',function(){
        var obj = $(this);
        var commentid = obj.data('commentid');
        if(typeof commentid == 'undefined' || commentid < 0){
            layer.alert('{lang delete_error}', {skin:'lyear-skin-danger'});
        }
        layer.confirm(__lang.delete_filenorecover_confirm, {title:__lang.delete_comment_confirm,skin:'lyear-skin-danger'}, function(index){
		$.post('{MOD_URL}&op=dynamic&do=deletecomment',{'id':commentid},function(data){
            layer.msg(__lang.deleting_not_please_close, {offset:'10px',time:0});
            if(data['success']){
                layer.msg(__lang.delete_success, {offset:'10px'});
                obj.parents('.dynameic-comment').html('');
            }else if(data['error']){
                layer.alert(data['error'], {skin:'lyear-skin-danger'});
            }
        },'json').fail(function (jqXHR, textStatus, errorThrown) {
            showmessage('操作失败，请稍后再试: ' + textStatus, 'error', 3000, 1);
        });
	});
    })
</script>